# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Rasmus Thomsen <oss@cogitri.dev>
pkgname=matrix-appservice-irc
pkgver=0.25.0
pkgrel=0
pkgdesc="Node.js IRC bridge for Matrix"
url="https://github.com/matrix-org/matrix-appservice-irc"
arch="x86 x86_64" # strip fails to strip binaries on other arches
license="Apache-2.0"
depends="nodejs>=12"
makedepends="npm python3"
subpackages="$pkgname-openrc"
source="https://github.com/matrix-org/matrix-appservice-irc/archive/$pkgver/matrix-appservice-irc-$pkgver.tar.gz
	matrix-appservice-irc.initd
	matrix-appservice-irc.confd"

case "$CARCH" in
	x86)
		options="textrels"
		;;
esac

build() {
	npm install
}

check() {
	npm test
}

package() {
	mkdir -p "$pkgdir"/etc/matrix-appservice-irc
	mkdir -p "$pkgdir"/usr/bin
	mkdir -p "$pkgdir"/usr/share/webapps/matrix-appservice-irc

	cp config.sample.yaml "$pkgdir"/etc/matrix-appservice-irc

	cp -r \
		"$builddir"/bin \
		"$builddir"/node_modules \
		"$builddir"/app.js \
		"$builddir"/config.schema.yml \
		"$builddir"/lib \
		"$builddir"/scripts \
		"$pkgdir"/usr/share/webapps/matrix-appservice-irc

	ln -s /usr/share/webapps/matrix-appservice-irc/bin/matrix-appservice-irc \
		"$pkgdir"/usr/bin/matrix-appservice-irc

	install -Dm755 "$srcdir"/matrix-appservice-irc.initd "$pkgdir"/etc/init.d/matrix-appservice-irc
	install -Dm644 "$srcdir"/matrix-appservice-irc.confd "$pkgdir"/etc/conf.d/matrix-appservice-irc
}

sha512sums="4e406c3b177f06371579de6935b406957e9ef5127427d79c20f474082d42425e99a04adeb7883b65aadd253aa5e6f8b338a83fa9c99ed35b18c4d364aad9499d  matrix-appservice-irc-0.25.0.tar.gz
c1cd9ebbf25c464159a05c369b3ff408e24aeb8beb8c06f336fb14b97ff15f9579b68c10f253f9cd207a117152510a4a49538064676bb2d1008434f985ef1c28  matrix-appservice-irc.initd
7b9e320a44cd07bb2876704eb1fa33dc0a8a6e237badf1e3d026d347df113eab144b42a0ad0e42b8f6e598c435e26982b37ef2ecdbd663fe34f34757e2e279cf  matrix-appservice-irc.confd"
